package com.sairobo.base.modules.sys.manager.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sairobo.base.common.constant.QueryConts;
import com.sairobo.base.common.entity.Page;
import com.sairobo.base.common.entity.Query;
import com.sairobo.base.modules.sys.dao.SysAttachMapper;
import com.sairobo.base.modules.sys.entity.SysAttach;
import com.sairobo.base.modules.sys.manager.SysAttachManager;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 附件表
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月17日 上午11:21:54
 */
@Component("sysAttachManager")
public class SysAttachManagerImpl extends ServiceImpl<SysAttachMapper,SysAttach> implements SysAttachManager {
    
	@Override
	public List<SysAttach> listSysAttach(Page<SysAttach> page, Query search) {
        EntityWrapper<SysAttach> ew=new EntityWrapper<SysAttach>();
        //搜索条件
        Map map = (HashMap)search.get(QueryConts.SEARCH_KEYWORD);
        String key = (String) map.get("key");
        //ew.like(true,"XXX",(String) map.get("key"));
        //ew.eq(true,"XXX",(String) map.get("key"));

        //if(StringUtils.isNotEmpty(key)){
        //   ew.andNew();
        //   ew.like(true,"nickName",key);
        //   ew.or();
        //   ew.like(true,"province",key);
        //   ew.or();
        //   ew.like(true,"city",key);
        //}

        //and (a like '%keyword%' or b like '%keyword%')
        //ew.andNew();
        //ew.like("a",keyword);
        //ew.or();
        //ew.like("b",keyword);

        ew.orderBy("id",false);
        //ew.orderBy("create_time",false);
        return baseMapper.selectPage(page,ew);
	}

	@Override
	public int saveSysAttach(SysAttach sysAttach) {
        return baseMapper.insert(sysAttach);
	}

	@Override
	public SysAttach getSysAttachById(Long id) {
        SysAttach test = baseMapper.selectById(id);
        return test;
	}

	@Override
	public int updateSysAttach(SysAttach sysAttach) {
        return baseMapper.updateById(sysAttach);
	}

	@Override
	public int batchRemove(Long[] id) {
        int count = baseMapper.deleteBatchIds(Arrays.asList(id));
        return count;
	}
	
}
